<form class="layui-form padding-r20" id="add-rule-panel">
    <div class="layui-form-item">
        <label class="layui-form-label">名称：</label>
        <div class="layui-input-block">
            <input type="text" model="role_name" required placeholder="请输入角色名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介：</label>
        <div class="layui-input-block">
            <textarea model="role_info" placeholder="请输入简介" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" id="btn-add-role" onclick="addRole()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    function addRole() {
        var data = getModel({ elem: "#add-rule-panel" });
        var validate = new Validate();
        var check = validate.check(data, [
            ['role_name', 'require', '角色名称'],
            ['role_info', 'require', '角色简介']
        ]);
        if (!check) {
            msg(validate.getError());
            return false;
        }
        $.post(api.role.add, data, function (res) {
            if (res.code) {
                msg('添加成功');
                reloadTable("roles");
                return true;
            }
            msg(res.msg);
        }, 'json');
    }
</script>